﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using WJ.DataSender.Service.Models;
using WJ.DataSender.Service.Models.ResultModel;
using Newtonsoft;
using Newtonsoft.Json;
using NLogManager;
using System.Threading.Tasks;
using WJ.DataSender.Service.Models.ConfigModel;
using WJ.DataSender.Service.Commen;
using System.Linq;
using System.Text;
using WJ.DataSender.Service.Implement;

namespace WJ.DataSender.Service
{
    /// <summary>
    /// 上报夜莺平台监控指标的处理引擎
    /// </summary>
    public class NightingaleMitricMessageHandle : BaseMessageHandle<NightingaleMitricRequestModel, NightingaleResutlModel>
    {
        private readonly PlatformInfo platform = CacheValues.AppsettingConfig.Platforms.Where(p => p.PlatformName == PlatformType.NIGHTINGALE.ToString()).FirstOrDefault(); 
        public NightingaleMitricMessageHandle(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
        {
            //获取对应平台接口对接信息
            PlatformUrl = platform.PlatformDomain+platform.ApiList[0].Route;
            PlatformName = platform.PlatformName;
            StopSend = platform.ApiList[0].StopSend;
        }

        /// <summary>
        /// 重写处理请求内容的方法
        /// </summary>
        /// <param name="method"></param>
        /// <param name="url"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public override HttpRequestMessage HandleRequest(HttpMethod method, string url, NightingaleMitricRequestModel message)
        {
            var request = new HttpRequestMessage(method, url);
            request.Headers.Add("Accept", "application/vnd.github.v3+json");
            request.Headers.Add("User-Agent", "HttpClientFactory-Sample");
            if (message != null)
            {
                request.Content = new StringContent(JsonConvert.SerializeObject(message.MitricModels), Encoding.UTF8);
            }
            return request;
        }

    }
}
